package com.simblog.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.simblog.common.constants.Constants;
import com.simblog.oaknt.domain.DataDict;
import com.simblog.oaknt.service.IDataDictService;

@Controller
@RequestMapping("p/data_dict")
public class DataDictController extends BaseController{
	
	private static final Logger logger = LoggerFactory.getLogger(DataDictController.class);
	
	@Reference
	private IDataDictService dataDictService;
	
	@ResponseBody
	@RequestMapping(value="query",method=RequestMethod.GET)
	public JSONObject query(String type,String pid,String name){
		logger.info("获取数据字典,type={},pid={},name={}",new Object[]{type,pid,name});
		Map<String,Object> params = new HashMap<String,Object>();
		
		try{
			params.put("type", type);
			params.put("pid", pid);
			params.put("name", name);
			List<DataDict> dataList = dataDictService.queryList(params); 
			logger.info("获取数据字典的length={}",(dataList == null) ? 0:dataList.size());
			return assemblyJson(dataList, Constants.RESP_SUCCESS, "获取字典成功");
		}catch (Exception e) {
			logger.error("获取数据字典异常" + e.getMessage());
			e.printStackTrace();
			return assemblyJson(null, Constants.RESP_EXCEPTION, "系统异常");
		}
	}
	
	
}
